package com.booking.springrestful.controller;

import com.booking.springrestful.domain.Approvaltable;
import com.booking.springrestful.domain.Users;
import com.booking.springrestful.domain.dto.ApprovaltableDto;
import com.booking.springrestful.resp.ResponseResult;
import com.booking.springrestful.service.ApprovaltableService;
import com.booking.springrestful.service.UsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
@RequestMapping("/filed")
//提交申请接口
public class filedController {

    @Resource
    private ApprovaltableService approvalTableService;


    @Resource
    private UsersService usersService;


    //提交申请
    @PostMapping
    private ResponseResult filedCounselor(HttpServletRequest request, @RequestBody Users users){
        String userName = request.getAttribute("userName").toString();
        usersService.userUpdate(userName,users);
        //记录到申请表
        approvalTableService.submit(userName);
        return ResponseResult.success();
    }


    //审批
    @PostMapping("/approval")
    private ResponseResult approval(@RequestBody ApprovaltableDto approvaltableDto){
        log.info(approvaltableDto.toString());
        approvalTableService.approval(approvaltableDto);
        return ResponseResult.success("审批成功");
    }


    //根据用户账号查询审批单
    @GetMapping("/getNote")
    private ResponseResult getNote(String username){
        String back=approvalTableService.getNote(username);
        return ResponseResult.success(back);
    }



    //再次提交申请
    @PostMapping("/again")
    private ResponseResult update(HttpServletRequest request, @RequestBody Users users){
        String userName = request.getAttribute("userName").toString();
        usersService.userUpdate(userName,users);
        //记录到申请表
        approvalTableService.again(userName);
        return ResponseResult.success();
    }




}
